package com.projectsquirrel;





import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class savedObservations extends ListActivity {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.savedobservations);
        File dir = getDir("observations",MODE_PRIVATE);
        InputStream in = null;
        byte[] bArray = new byte[1024];
        try {
          in = new BufferedInputStream(new FileInputStream(dir));
          while(in.read(bArray)!=-1){
        	  
          }
        }
        catch(Exception e){
        	
        }
        if (in != null) {
	  		try {
				in.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	  	}
        String[] fileNames = fileList();              
        setListAdapter(new ArrayAdapter<String>(this,  android.R.layout.simple_list_item_1, fileNames));      
    }
	@Override
	public void onResume() {
		super.onResume();
		getDir("observations",MODE_PRIVATE);
        String[] fileNames = fileList();              
        setListAdapter(new ArrayAdapter<String>(this,  android.R.layout.simple_list_item_1, fileNames));      
    }
	@Override
	public void onRestart() {
		super.onRestart();
		getDir("observations",MODE_PRIVATE);
        String[] fileNames = fileList();              
        setListAdapter(new ArrayAdapter<String>(this,  android.R.layout.simple_list_item_1, fileNames));      
    }
	@Override
	public void onPause() {
		super.onPause();
        //final ListView list = (ListView) findViewById(android.R.layout.simple_list_item_1);
		getDir("observations",MODE_PRIVATE);
        String[] fileNames = fileList();              
        setListAdapter(new ArrayAdapter<String>(this,  android.R.layout.simple_list_item_1, fileNames));
    }
	@Override
    protected void onListItemClick(ListView l, View v, int position, long id) 
    {    
		String filename = ((TextView) v).getText().toString();		
		Intent i = new Intent(savedObservations.this, displayObservation.class);
		i.putExtra("FileName", filename);
		startActivity(i);   
		
    }
	
	
	
}